/*-------------------------------------------------------------------------------------------------------------------------
	COMBUSTIBLE LEMONS!
-------------------------------------------------------------------------------------------------------------------------*/

local PLUGIN = {}
PLUGIN.Title = "Lemons"
PLUGIN.Description = "I'M THE MAN WHOS GUNNA BURN YOUR HOUSE DOWN, WITH THE LEMONS!"
PLUGIN.Author = "Divran + Matt J"
PLUGIN.ChatCommand = "lemons"
PLUGIN.Usage = "[players]"
PLUGIN.Privileges = { "lemons" }

function PLUGIN:Call( ply, args )
	if ( ply:EV_HasPrivilege( "lemons" ) ) then
		local players = evolve:FindPlayer( args, ply )
		
		for _, pl in ipairs( players ) do
			pl:SetMoveType( MOVETYPE_WALK )
			self:SpawnTrain( pl:GetPos() + pl:GetForward() * 1000 + Vector(0,0,50), pl:GetForward() * -1 )
		end
		
		if ( #players > 0 ) then
			evolve:Notify( evolve.colors.red, evolve:CreatePlayerList( players ), evolve.colors.white, " got ignited by Combustible Lemons." )
		else
			evolve:Notify( ply, evolve.colors.red, "No matching players found." )
		end
	else
		evolve:Notify( ply, evolve.colors.red, evolve.constants.notallowed )
	end
end

function PLUGIN:SpawnTrain( Pos, Direction )
    local train = ents.Create( "lemon" )
    train:SetAngles( Direction:Angle() )
    train:SetPos( Pos )
    train:Spawn()
    train:Activate()
    train:EmitSound( "lemongrenade/-LEMON.wav", 100, 100 )
    train:GetPhysicsObject():SetVelocity( Direction * 50000 )
     
    timer.Create( "TrainRemove_"..CurTime(), 5, 1, function( train ) train:Remove() end, train )
end
 
local MyCodeEnt = {}
  
MyCodeEnt.Type = "anim"
  
if SERVER then
    function MyCodeEnt:Initialize()
        self:SetModel("models/houseburning/houseburning.mdl")
        self:PhysicsInit(SOLID_VPHYSICS)
        self:SetSolid(SOLID_VPHYSICS)
    end
    function MyCodeEnt:StartTouch(ent)
        if ent:IsPlayer() then
            ent:Ignite(10,0)
        end
    end
else
  
   function MyCodeEnt:Draw()
        self:DrawModel()
   end
  
end
scripted_ents.Register(MyCodeEnt, "lemon", true)

function PLUGIN:Menu( arg, players )
	if ( arg ) then
		RunConsoleCommand( "ev", "lemons", unpack( players ) )
	else
		return "Lemons", evolve.category.punishment
	end
end

evolve:RegisterPlugin( PLUGIN )